<?php

// 红包表

namespace app\console\model;

use think\Db;
use think\Model;
use think\Request;
use app\console\model\MemberMessage as MemberMessageModel;

class RedPacket extends Model
{
    // 模型事件
    protected static function init()
    {

        // 写入前
        self::event('before_write', function ($data) {
            $interval_timer = explode(' / ', Request::instance()->param('interval_timer'));
            $data->start_time = strtotime($interval_timer[0]);
            $data->end_time = strtotime($interval_timer[1]);

        });

        // self::event('after_insert',function ($data) {
        //     $information = Request::instance()->param();
        //    $str = Db::name('red_packet_rule')->where('id',$information['pid'])->value('red_str');
        //
        //    $new_id = $data->id;
        //    if (empty($str)){
        //        $str = $new_id;
        //    }else{
        //        $str = $str.",".$new_id;
        //    }
        //
        //    Db::name('red_packet_rule')->where('id',$data['pid'])->update(['red_str'=>$str]);
        // });

        // 新增后
        // self::event('after_insert', function ($data) {
        //     $model = new MemberMessageModel();
        //     $model->save(['member_id' => '0', 'title' => $data->title, 'content' => $data->content, 'create_time' => date('Y-m-d H:i:s',time())]);
        // });

    }
}